﻿/************************************************
 * SpeechService.cs
 * This class carries out the conversion from text to audio 
***********************************************/

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Speech.Synthesis;

namespace SharePointExplorer.Classes
{
    public class SpeechService
    {
        #region declarations
        SpeechSynthesizer synth;
        #endregion

        /// <summary>
        /// Constructor
        /// </summary>
        public SpeechService()
        {
            synth = new SpeechSynthesizer();
        }

        public enum Operation
        {
            Copy,
            Delete,
            Move
        }

        public enum OperationType
        {
            Before,
            After
        }


        /// <summary>
        /// "Speaks" the mentioned operation
        /// </summary>
        /// <param name="operation">Move, Copy, Delete</param>
        /// <param name="type">Before, After</param>
        public void SpeakOperation(Operation operation, OperationType type)
        {
            PromptBuilder builder = new PromptBuilder(new System.Globalization.CultureInfo("en-US"));
            var voice = synth.GetInstalledVoices().FirstOrDefault();
            synth.SelectVoice(voice.VoiceInfo.Name);
            if (type == OperationType.Before)
            {
                switch (operation)
                {
                    case Operation.Copy:
                        builder.AppendText(operation.ToString() + " Operation Enabled. Please select the file to copy.");
                        break;

                    case Operation.Move:
                        builder.AppendText(operation.ToString() + " Operation Enabled. Please select the file to move.");
                        break;

                    case Operation.Delete:
                        builder.AppendText(operation.ToString() + " Operation Enabled. Please select the file to delete.");
                        break;
                }
            }
            else if (type == OperationType.After)
            {
                switch (operation)
                {
                    case Operation.Copy:
                        builder.AppendText("Please select a target list.");
                        break;

                    case Operation.Move:
                        builder.AppendText("Please select a target list.");
                        break;

                    case Operation.Delete:
                        break;
                }
            }

            synth.Volume = 100;
            synth.SpeakAsync(builder);
        }

        /// <summary>
        /// Reads Text out loud
        /// </summary>
        /// <param name="Text">Text to read</param>
        public void ReadText(string Text)
        {
            PromptBuilder builder = new PromptBuilder(new System.Globalization.CultureInfo("en-US"));
            var voice = synth.GetInstalledVoices().FirstOrDefault();
            synth.SelectVoice(voice.VoiceInfo.Name);
            builder.AppendText(Text);
            synth.SetOutputToDefaultAudioDevice();
            synth.Volume = 100;
            synth.SpeakAsync(builder);
        }
    }
}
